package edu.kit.csl.pisa.training.eva2;

/*
This file is part of the PISA Alignment Tool.

Copyright (C) 2013
Karlsruhe Institute of Technology
Cognitive Systems Lab (CSL)
Felix Stahlberg

PISA is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PISA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PISA. If not, see <http://www.gnu.org/licenses/>.
*/

import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.operators.distancemetric.InterfaceDistanceMetric;

/**
 * This class implements a distance metric for alignments. The distance of
 * two alignments is the number of displaced alignment points on word level
 * on the target language side.
 * 
 * @see edu.kit.csl.pisa.datatypes.Alignment#
 * 		distanceTo(edu.kit.csl.pisa.datatypes.Alignment)
 */
public class DisplacedAlignmentPointsMetric implements InterfaceDistanceMetric {

	/* (non-Javadoc)
	 * @see java.lang.Object#clone()
	 */
    public Object clone() {
        return (Object) new DisplacedAlignmentPointsMetric();
    }
    
	/**
	 * Counts the misplaced alignment points between the alignments on word
	 * level. If the lengths of the alignments are not equal, we add the
	 * offset to the number of misplaced alignment points.
	 * {@inheritDoc}
	 * @see edu.kit.csl.pisa.datatypes.Alignment#
	 * 		distanceTo(edu.kit.csl.pisa.datatypes.Alignment)
	 * @throws InvalidCastException if one of the individuals have no alignment
	 */
	@Override
	public double distance(AbstractEAIndividual indy1,
			AbstractEAIndividual indy2) {
		return ((InterfaceDataTypeSentenceAlignment) indy1)
				.getSentenceAlignment().getAlignment()
				.distanceTo(((InterfaceDataTypeSentenceAlignment) indy2)
						.getSentenceAlignment().getAlignment());
	}

}
